<!DOCTYPE html>
<html lang="zh">
<head>
    <include file="index/index_style" title="管理后台"/>
</head>
<body class="navbar-fixed">
<!-- header -->
<include file="index/header"/>
<!-- / header -->

<!-- menu -->
<include file="index/menu" news="active"/>
<!-- / menu -->

<section id="content">
    <section class="main padder">
        <div class="clearfix">
            <h4><i class="icon-table"></i>新闻列表</h4>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <!-- .breadcrumb -->
                <ul class="breadcrumb">
                    <li><a href="#"><i class="icon-home"></i>主页</a></li>
                    <li><a href="#"><i class="icon-file-text"></i>新闻</a></li>
                    <li class="active">列表</li>
                </ul>
                <!-- / .breadcrumb -->
            </div>
            <div class="col-lg-12">
                <section class="panel">
                    <div class="pull-out">
                        <table id="news" class="table table-bordered table-striped m-b-none">
                            <thead>
                            <tr>
                                <th width="40%">标题</th>
                                <th width="20%">发布者</th>
                                <th width="20%">发布时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </section>
            </div>
        </div>
    </section>
</section>

<!-- .modal -->
<div id="add-tag" class="modal fade">
    <form class="m-b-none">
        <div class="modal-dialog pos-abt" style="margin-top:-235px; top:50%">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i
                            class="icon-remove"></i></button>
                    <h4 class="modal-title" id="">添加标签</h4>
                </div>
                <div class="modal-body">
                    <div class="block">
                        <label class="control-label">名称</label>
                        <input id="tagname" name="name" type="text" class="form-control" placeholder="名称">
                    </div>

                    <!-- 提示消息 -->
                    <div class="alert alert-warning message-alert-box" style="display: none">
                        <i class="icon-bell-alt"></i><strong><span class="message-alert"></span></strong>
                    </div>

                    <div class="alert alert-success message-success-box" style="display: none">
                        <i class="icon-ok-sign icon-large"></i><strong><span class="message-success"></span></strong>
                    </div>


                </div>
                <div class="modal-footer">
                    <button id="submit" type="button" class="btn btn-small btn-primary">保存</button>
                </div>
            </div><!-- /.modal-content -->
        </div>
    </form>
</div>
<!-- / .modal -->


<script src="__PUBLIC__/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="__PUBLIC__/js/bootstrap.js"></script>
<!-- fuelux -->
<script src="__PUBLIC__/js/fuelux/fuelux.js"></script>
<script src="__PUBLIC__/js/underscore-min.js"></script>
<!-- datatables -->
<script src="__PUBLIC__/js/datatables/jquery.dataTables.js"></script>
<script src="__PUBLIC__/js/datatables/dataTables.bootstrap.js"></script>
<!-- Sparkline Chart -->
<script src="__PUBLIC__/js/charts/sparkline/jquery.sparkline.min.js"></script>
<!-- Easy Pie Chart -->
<script src="__PUBLIC__/js/charts/easypiechart/jquery.easy-pie-chart.js"></script>

<!-- app -->
<script src="__PUBLIC__/js/app.js"></script>
<script src="__PUBLIC__/js/app.plugin.js"></script>
<script src="__PUBLIC__/js/app.data.js"></script>

<!-- page script -->
<script>

    $(function(){
        $('#news').dataTable({

            "bPaginate": true,
            "bProcessing": false,                //是否显示正在处理提示信息。
            "bLengthChange": true,
            "bFilter": true,                    //是否使用内置的过滤功能。
            "bSort": true,
            "bInfo": true,
            "bAutoWidth": false,
            "bStateSave": true,
            "iDisplayLength": 10,               //每页显示10条数据
            "aaSorting": [[1, "desc"]],         //默认排序 第2列

            "bServerSide": true,
            "sAjaxSource": "{:U('Admin/News/newsList/')}",
            "sServerMethod": "POST",

            "aoColumns": [
                {
                    "sTitle":"标题",
                    "mData": "title",
                    'sClass': "text-center",
                    "mRender": function (data, type, full) {
                        return "<a href='javascript:void(0)' onclick='edtPrd(" + full['nid'] + ")'>" + data + "</a>";
                    }
                },
                {
                    "sTitle":"发布者",
                    "mData": "publisher",
                    'sClass': "text-center"
//                    "mRender": function (data){
//                        return new Date(parseInt(data) * 1000).toLocaleDateString();
//                    }
                },
                {
                    "sTitle":"发布时间",
                    "mData": "pubtime",
                    'sClass': "text-center",
                    "mRender": function (data){
                        return new Date(parseInt(data) * 1000).toLocaleDateString();
                    }
                }
            ],

            "aoColumnDefs": [                           //和aoColums类似，但他可以给指定列附近爱属性
                {"bSortable": false, "aTargets": [0,1]}   //1列不能排序
            ],

            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sSearch": "搜索:"
            }

        });
    });

    //编辑
    function edtPrd(id){
        window.location.href = "{:U('/Home/News/"+id+"')}";
    }


    //删除
    function delAct(id){

        $("#delete_confirm").modal("show");

        $("#confirm").click(function () {

            var dialog = $('#delete_tips');
            var content = $("#tips_content");
            var table = $("#activity");

            $.ajax({
                "method" : "post",
                "url"    : "/?s=Admin/Activity/delActivity/",
                "data"   : {"id":id},
                success: function(data){
                    if(data==1){
                        content.html("删除成功");
                    }else{
                        content.html("删除失败");
                    }
                    //刷新表格
                    table.dataTable().fnPageChange('previous',true);

                    dialog.modal('show');
                },
                error: function(){
                    content.html("服务器无响应,请再试一次");
                    dialog.modal('show');
                }
            });

        });

    }
</script>
</body>
</html>